function ListNode(val, next) {
  this.val = val === undefined ? 0 : val
  this.next = next === undefined ? null : next
}

function printListNode(list) {
  const arr = []
  for (let p = list; p; p = p.next) {
    arr.push(p.val)
  }

  console.log(arr)
}

/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var addTwoNumbers = function (l1, l2) {

}

function arrToList(arr) {
  const dummy = new ListNode(Infinity)
  let tail = dummy
  arr.forEach(v => {
    tail.next = new ListNode(v)
    tail = tail.next
  })

  return dummy.next
}

function listToArr(list, dummy = false) {
  const arr = []
  for (let p = dummy ? list.next : list; p; p = p.next) {
    arr.push(p.val)
  }

  return arr
}

const l1 = new ListNode(2, new ListNode(4, new ListNode(3)))
const l2 = new ListNode(5, new ListNode(6, new ListNode(4)))
console.log(listToArr(addTwoNumbers(l1, l2))) // [7, 0, 8]
